package com.edu.chat.web.shared;

import com.edu.buservice.util.model.TenantUtil;
import com.edu.chat.facade.facade.RecallFacade;
import com.edu.chat.facade.facade.SessionFacade;
import com.edu.chat.facade.model.dto.SessionInfoDetailDTO;
import com.edu.chat.web.common.model.R;
import com.edu.chat.web.service.CsSessionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: KQAIA
 * @description:
 * @author: 无恙
 * @create: 2025-03-30 18:18
 **/

@DubboService(interfaceClass = SessionFacade.class)
@Service
@Slf4j
public class SessionFacadeImpl implements SessionFacade {


	@Autowired
	private CsSessionService csSessionService;

	@Override
	public SessionInfoDetailDTO getSessionInfo(String sessionId, String tenantId) {

		TenantUtil.setCurrentTenantId(tenantId);
		try{

			R<SessionInfoDetailDTO> sessionInfo = csSessionService.getSessionInfo(sessionId);

			if(R.isSuccess(sessionInfo)){
				return sessionInfo.getData();
			}

			return null;
		}catch (Exception e){
			log.info("getSessionInfo error:{}",e.getMessage());
			return null;
		}finally {
			TenantUtil.clear();
		}
	}

	@Override
	public boolean updateSessionName(String sessionId, String sessionName, String tenantId) {

		TenantUtil.setCurrentTenantId(tenantId);

		try{
			R<Boolean> updateSessionName = csSessionService.updateSessionName(sessionId, sessionName);

			if(R.isSuccess(updateSessionName)){
				return updateSessionName.getData();
			}

			return false;
		}catch (Exception e){
			log.info("updateSessionName error:{}",e.getMessage());

			return false;
		}finally {
			TenantUtil.clear();
		}
	}
}
